extern uniform float4x4 gWorldInvTran;
extern uniform float4x4	gWVP;
extern uniform float4	gColor;
extern uniform float3	gLightDir;
extern uniform texture	gToonShade;

sampler ToonShadeS = sampler_state
{
	Texture = <gToonShade>;
	MinFilter = POINT;
	MagFilter = POINT;
	MipFilter = POINT;
};

void VS(float3 posL : POSITION0, 
		float3 normalL : NORMAL0,
		out float4 posH : POSITION0,
		out float2 texCoord : TEXCOORD0,
		out float4 diffuse : COLOR0)
{
	posH = mul(float4(posL, 1.0f), gWVP);

	float3 normalW = mul(float4(normalL, 0.0f), gWorldInvTran).xyz;
	float3 lightDir = normalize(gLightDir);
	normalW = normalize(normalW); 
	float u = max(dot(normalW, lightDir), 0.0f);

	texCoord.x = u;
	texCoord.y = 0.5f;
	
	diffuse = gColor;
}

float4 PS(float2 texCoord : TEXCOORD0, float4 diffuse : COLOR0) : COLOR0
{
	return tex2D(ToonShadeS, texCoord) * diffuse;
}

technique ToonTech
{
	pass P0
	{
		vertexShader = compile vs_2_0 VS();
		pixelShader  = compile ps_2_0 PS();
	}
}
